﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TekaMUD.Engine.Blocks;
using TekaMUD.Engine.IO;

namespace TekaMUD.Engine.Commands
{
	public class ManagementCommands
	{
		/// <summary>
		/// Sets global variables.
		/// </summary>
		/// <param name="c"></param>
		public static void Set(Command c)
		{
			using (ChannelOutputHolder coh = new ChannelOutputHolder(c.Channel))
			{
				if (c.CommandNode.ArgumentList.Count == 0)
				{
					Messenger.SendAgent(c.Player, "Runtime options:\r\n");

					foreach (KeyValuePair<RuntimeOption, object> kvp in RuntimeOptions.ListAllOptions())
						Messenger.SendAgent(c.Player, "\t" + kvp.Key + "\t = \t" + kvp.Value + "\r\n");

					Messenger.SendAgent(c.Player, "\r\n");
					return;
				}

                if(c.CommandNode.ArgumentList[0].NounComponents.Length != 3 || c.CommandNode.ArgumentList[0].NounComponents[1] != "=")
                {
                    Messenger.SendAgent(c.Player, "\nUsage: set <option> = <value>");
                    return;
                }


                string lval = c.CommandNode.ArgumentList[0].NounComponents[0];
                string rval = c.CommandNode.ArgumentList[0].NounComponents[2];

				try
				{
					RuntimeOptions.SetOption(lval, rval);
				}
				catch (Exception ex)
				{
					Messenger.SendAgent(c.Player, "Error setting parameter: " + ex.Message + "\r\n");
					return;
				}

				Messenger.SendAgent(c.Player, "[" + lval + "] set to [" + rval + "] successfully.\r\n");
			}
		}
	}
}
